#############################################################################
# Copyright (c) 2009 Dmitry Grushin <dgrushin@gmail.com>.
#
# This file is part of clupower (cluster power manager utility)
#
# Clupower is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Clupower is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Clupower.  If not, see <http://www.gnu.org/licenses/>.
#
# Contributors:
#    Dmitry Grushin <dgrushin@gmail.com> - initial API and implementation
#############################################################################

$:.unshift File.join(File.dirname(__FILE__),'..','lib')

require 'algo'

class TestMinWidthAlgo < Test::Unit::TestCase

  def setup
    $settings_path = File.dirname(__FILE__)
    $settings_file = "settings.test3.yaml"

    Settings.instance.load
  end

  def test1
    CPMonitor.instance.log_message("---------- TEST3.1 START ----------")
    decision = Settings.instance.pm_algo.manage(["node3.ispras.ru"], [])
    assert(decision.nodes_on == ["node3.ispras.ru"])
    assert(decision.nodes_sleep.empty?)
  end

  def test2
    Settings.instance.config['CMD_PBSNODES'] = "test/dumps/pbsnodes3"
    CPMonitor.instance.log_message("---------- TEST3.2 START ----------")
    wait_list = []
    wait_list << JobsWaitNodes.new(["2"], ["node3.ispras.ru"]).wait #offline node
    wait_list << JobsWaitNodes.new(["3"], ["node2.ispras.ru"]).wait #online node
    decision = Settings.instance.pm_algo.manage([], wait_list)
    wait_list.each { |wl| wl.join }
    assert(decision.nodes_on.empty?)
    assert(decision.nodes_sleep.empty?)
  end
end
